<?php

namespace Admin\Controller;

use Admin\Controller\IndexController;
use Application\Model\DBO\BookingOnlineDBO;

class OrderOnlineManagementController extends IndexController {

    public $userTable;

    public function indexAction() {
        // kiem tra neu chua dang nhap thi quay ve lai trang dang nhap
        $this->checkRole2();
        // Neu dang nhap roi thi hien thi len sach sach nguoi dung
        // Lay thuc the dang nhap dua ra layout
        $this->layout()->identity = $this->getAuthService()->getIdentity();
        // Hien thi dua sanh sach đăng ký mượn sách online ra view
        $objectOrderOnlineDBO = new BookingOnlineDBO($this->getServiceLocator());
        $paginator = $objectOrderOnlineDBO->getAllBookOrder();
        $paginator->setCurrentPageNumber((int) $this->params()->fromQuery('page', 1));
        $paginator->setItemCountPerPage(10);
        $paginator->setPageRange(5);
        return array(
            'paginator' => $paginator,
        );
    }

    public function applyAction() {
        $bookID = $this->params()->fromRoute('id', 0);
        $objectOrderOnlineDBO = new BookingOnlineDBO($this->getServiceLocator());
        $objectOrderOnlineDBO->applyBorrowBookOnline($bookID);
        return $this->redirect()->toRoute('order-online-management');
    }

    public function denyAction() {
        $bookID = $this->params()->fromRoute('id', 0);
        $objectOrderOnlineDBO = new BookingOnlineDBO($this->getServiceLocator());
        $objectOrderOnlineDBO->denyBorrowBookOnline($bookID);
        return $this->redirect()->toRoute('order-online-management');
    }

    public function deleteAction() {
        $bookID = $this->params()->fromRoute('id', 0);
        $objectOrderOnlineDBO = new BookingOnlineDBO($this->getServiceLocator());
        $objectOrderOnlineDBO->deleteBorrowBookOnline($bookID);
        return $this->redirect()->toRoute('order-online-management');
    }

}

